package nl.saxion.saktiehuis.sligroservice;

import nl.saxion.saktiehuis.bestelservice.model.Bestelling;
import nl.saxion.saktiehuis.bestelservice.model.Product;

import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractTransformer;
import org.mule.transformer.types.DataTypeFactory;



public class SligroTransformer  extends AbstractTransformer{

	public SligroTransformer(){
		registerSourceType(DataTypeFactory.create(Bestelling.class));
		setReturnDataType(DataTypeFactory.create(nl.saxion.saktiehuis.sligroservice.Bestelling.class));
		setName("SligroTransformer");
	}
	
	@Override
	protected Object doTransform(Object src, String enc)
			throws TransformerException {
		
		System.out.println("Transforming bestelling");
		Bestelling sourceBestelling = (Bestelling) src;
		nl.saxion.saktiehuis.sligroservice.Bestelling targetBestelling = new nl.saxion.saktiehuis.sligroservice.Bestelling();
		
		targetBestelling.setKlantNaam(sourceBestelling.getKlantNaam());
		targetBestelling.setOrderNr(sourceBestelling.getBestelNr());
		for (Product sourceProduct: sourceBestelling.getProducten()){
			targetBestelling.getProducten().add(transformProduct(sourceProduct));
		}
		return targetBestelling;
	}
	
	private nl.saxion.saktiehuis.sligroservice.Product transformProduct(Product sourceProduct){
		nl.saxion.saktiehuis.sligroservice.Product targetProduct = new nl.saxion.saktiehuis.sligroservice.Product();
		targetProduct.setProductNaam(sourceProduct.getProductNaam());
		return targetProduct;
	}

	
}
